package Rangel.common.world.info;

import Rangel.common.world.helper.RangelWorldHelper;
import javolution.util.FastSet;
import rescuecore2.worldmodel.EntityID;

import java.util.ArrayList;
import java.util.Set;


public class CivilianInfo {//市民信息

    protected RangelWorldHelper world;
    private final Set<EntityID> possibleBuildings = new FastSet<>();//可能存在的建筑物
    private boolean isFound = false;
    int voiceRange;//声音范围

    public CivilianInfo(RangelWorldHelper world) {
        this.world = world;
        voiceRange = world.getVoiceRange();
    }

    public void updatePossibleBuilding(ArrayList<EntityID> possibleList) {//更新可能的建筑物
        if (isFound) {
            return;
        }
        if (possibleBuildings.isEmpty()) {
            possibleBuildings.addAll(possibleList);
        } else {
            ArrayList<EntityID> toRemove = new ArrayList<>();
            for (EntityID building : possibleBuildings) {
                if (!possibleList.contains(building) && world.getVisitedBuildings().contains(building)) {//搜寻过的建筑物
                    toRemove.add(building);
                }
            }
            possibleBuildings.removeAll(toRemove);
        }
    }

    public Set<EntityID> getPossibleBuildings() {
        return possibleBuildings;
    }

    public void clearPossibleBuildings() {
        isFound = true;
        possibleBuildings.clear();
    }
}